package com.google.android.material.internal;

import android.animation.TimeInterpolator;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.os.Build;
import android.text.TextPaint;
import android.text.TextUtils;
import android.view.View;
import b.f.j.e;
import b.f.l.s;
import c.b.a.b.z.a;
import c.b.a.b.z.d;

public final class a {
    private static final boolean V = (Build.VERSION.SDK_INT < 18);
    private static final Paint W;
    private boolean A;
    private Bitmap B;
    private Paint C;
    private float D;
    private float E;
    private float F;
    private float G;
    private int[] H;
    private boolean I;
    private final TextPaint J;
    private final TextPaint K;
    private TimeInterpolator L;
    private TimeInterpolator M;
    private float N;
    private float O;
    private float P;
    private ColorStateList Q;
    private float R;
    private float S;
    private float T;
    private ColorStateList U;

    /* renamed from: a  reason: collision with root package name */
    private final View f2317a;

    /* renamed from: b  reason: collision with root package name */
    private boolean f2318b;

    /* renamed from: c  reason: collision with root package name */
    private float f2319c;

    /* renamed from: d  reason: collision with root package name */
    private final Rect f2320d;
    private final Rect e;
    private final RectF f;
    private int g = 16;
    private int h = 16;
    private float i = 15.0f;
    private float j = 15.0f;
    private ColorStateList k;
    private ColorStateList l;
    private float m;
    private float n;
    private float o;
    private float p;
    private float q;
    private float r;
    private Typeface s;
    private Typeface t;
    private Typeface u;
    private c.b.a.b.z.a v;
    private c.b.a.b.z.a w;
    private CharSequence x;
    private CharSequence y;
    private boolean z;

    /* renamed from: com.google.android.material.internal.a$a  reason: collision with other inner class name */
    class C0101a implements a.C0092a {
        C0101a() {
        }

        public void a(Typeface typeface) {
            a.this.L(typeface);
        }
    }

    class b implements a.C0092a {
        b() {
        }

        public void a(Typeface typeface) {
            a.this.T(typeface);
        }
    }

    static {
        Paint paint = null;
        W = paint;
        if (paint != null) {
            paint.setAntiAlias(true);
            W.setColor(-65281);
        }
    }

    public a(View view) {
        this.f2317a = view;
        this.J = new TextPaint(129);
        this.K = new TextPaint(this.J);
        this.e = new Rect();
        this.f2320d = new Rect();
        this.f = new RectF();
    }

    private static boolean A(float f2, float f3) {
        return Math.abs(f2 - f3) < 0.001f;
    }

    private static float C(float f2, float f3, float f4, TimeInterpolator timeInterpolator) {
        if (timeInterpolator != null) {
            f4 = timeInterpolator.getInterpolation(f4);
        }
        return c.b.a.b.m.a.a(f2, f3, f4);
    }

    private static boolean F(Rect rect, int i2, int i3, int i4, int i5) {
        return rect.left == i2 && rect.top == i3 && rect.right == i4 && rect.bottom == i5;
    }

    private boolean M(Typeface typeface) {
        c.b.a.b.z.a aVar = this.w;
        if (aVar != null) {
            aVar.c();
        }
        if (this.s == typeface) {
            return false;
        }
        this.s = typeface;
        return true;
    }

    private boolean U(Typeface typeface) {
        c.b.a.b.z.a aVar = this.v;
        if (aVar != null) {
            aVar.c();
        }
        if (this.t == typeface) {
            return false;
        }
        this.t = typeface;
        return true;
    }

    private void W(float f2) {
        g(f2);
        boolean z2 = V && this.F != 1.0f;
        this.A = z2;
        if (z2) {
            j();
        }
        s.W(this.f2317a);
    }

    private static int a(int i2, int i3, float f2) {
        float f3 = 1.0f - f2;
        return Color.argb((int) ((((float) Color.alpha(i2)) * f3) + (((float) Color.alpha(i3)) * f2)), (int) ((((float) Color.red(i2)) * f3) + (((float) Color.red(i3)) * f2)), (int) ((((float) Color.green(i2)) * f3) + (((float) Color.green(i3)) * f2)), (int) ((((float) Color.blue(i2)) * f3) + (((float) Color.blue(i3)) * f2)));
    }

    /* JADX WARNING: Removed duplicated region for block: B:13:0x0069  */
    /* JADX WARNING: Removed duplicated region for block: B:16:0x0079  */
    /* JADX WARNING: Removed duplicated region for block: B:20:0x008d  */
    /* JADX WARNING: Removed duplicated region for block: B:23:0x00a3  */
    /* JADX WARNING: Removed duplicated region for block: B:26:0x00cb  */
    /* JADX WARNING: Removed duplicated region for block: B:30:0x00dc  */
    /* JADX WARNING: Removed duplicated region for block: B:33:0x00ea  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void b() {
        /*
            r11 = this;
            float r0 = r11.G
            float r1 = r11.j
            r11.g(r1)
            java.lang.CharSequence r1 = r11.y
            r2 = 0
            r3 = 0
            if (r1 == 0) goto L_0x0018
            android.text.TextPaint r4 = r11.J
            int r5 = r1.length()
            float r1 = r4.measureText(r1, r2, r5)
            goto L_0x0019
        L_0x0018:
            r1 = 0
        L_0x0019:
            int r4 = r11.h
            boolean r5 = r11.z
            int r4 = b.f.l.c.b(r4, r5)
            r5 = r4 & 112(0x70, float:1.57E-43)
            r6 = 80
            r7 = 48
            r8 = 1073741824(0x40000000, float:2.0)
            if (r5 == r7) goto L_0x0053
            if (r5 == r6) goto L_0x004d
            android.text.TextPaint r5 = r11.J
            float r5 = r5.descent()
            android.text.TextPaint r9 = r11.J
            float r9 = r9.ascent()
            float r5 = r5 - r9
            float r5 = r5 / r8
            android.text.TextPaint r9 = r11.J
            float r9 = r9.descent()
            float r5 = r5 - r9
            android.graphics.Rect r9 = r11.e
            int r9 = r9.centerY()
            float r9 = (float) r9
            float r9 = r9 + r5
            r11.n = r9
            goto L_0x0061
        L_0x004d:
            android.graphics.Rect r5 = r11.e
            int r5 = r5.bottom
            float r5 = (float) r5
            goto L_0x005f
        L_0x0053:
            android.graphics.Rect r5 = r11.e
            int r5 = r5.top
            float r5 = (float) r5
            android.text.TextPaint r9 = r11.J
            float r9 = r9.ascent()
            float r5 = r5 - r9
        L_0x005f:
            r11.n = r5
        L_0x0061:
            r5 = 8388615(0x800007, float:1.1754953E-38)
            r4 = r4 & r5
            r9 = 5
            r10 = 1
            if (r4 == r10) goto L_0x0079
            if (r4 == r9) goto L_0x0073
            android.graphics.Rect r1 = r11.e
            int r1 = r1.left
            float r1 = (float) r1
            r11.p = r1
            goto L_0x0084
        L_0x0073:
            android.graphics.Rect r4 = r11.e
            int r4 = r4.right
            float r4 = (float) r4
            goto L_0x0081
        L_0x0079:
            android.graphics.Rect r4 = r11.e
            int r4 = r4.centerX()
            float r4 = (float) r4
            float r1 = r1 / r8
        L_0x0081:
            float r4 = r4 - r1
            r11.p = r4
        L_0x0084:
            float r1 = r11.i
            r11.g(r1)
            java.lang.CharSequence r1 = r11.y
            if (r1 == 0) goto L_0x0097
            android.text.TextPaint r3 = r11.J
            int r4 = r1.length()
            float r3 = r3.measureText(r1, r2, r4)
        L_0x0097:
            int r1 = r11.g
            boolean r2 = r11.z
            int r1 = b.f.l.c.b(r1, r2)
            r2 = r1 & 112(0x70, float:1.57E-43)
            if (r2 == r7) goto L_0x00cb
            if (r2 == r6) goto L_0x00c5
            android.text.TextPaint r2 = r11.J
            float r2 = r2.descent()
            android.text.TextPaint r4 = r11.J
            float r4 = r4.ascent()
            float r2 = r2 - r4
            float r2 = r2 / r8
            android.text.TextPaint r4 = r11.J
            float r4 = r4.descent()
            float r2 = r2 - r4
            android.graphics.Rect r4 = r11.f2320d
            int r4 = r4.centerY()
            float r4 = (float) r4
            float r4 = r4 + r2
            r11.m = r4
            goto L_0x00d9
        L_0x00c5:
            android.graphics.Rect r2 = r11.f2320d
            int r2 = r2.bottom
            float r2 = (float) r2
            goto L_0x00d7
        L_0x00cb:
            android.graphics.Rect r2 = r11.f2320d
            int r2 = r2.top
            float r2 = (float) r2
            android.text.TextPaint r4 = r11.J
            float r4 = r4.ascent()
            float r2 = r2 - r4
        L_0x00d7:
            r11.m = r2
        L_0x00d9:
            r1 = r1 & r5
            if (r1 == r10) goto L_0x00ea
            if (r1 == r9) goto L_0x00e4
            android.graphics.Rect r1 = r11.f2320d
            int r1 = r1.left
            float r1 = (float) r1
            goto L_0x00f3
        L_0x00e4:
            android.graphics.Rect r1 = r11.f2320d
            int r1 = r1.right
            float r1 = (float) r1
            goto L_0x00f2
        L_0x00ea:
            android.graphics.Rect r1 = r11.f2320d
            int r1 = r1.centerX()
            float r1 = (float) r1
            float r3 = r3 / r8
        L_0x00f2:
            float r1 = r1 - r3
        L_0x00f3:
            r11.o = r1
            r11.h()
            r11.W(r0)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.internal.a.b():void");
    }

    private void d() {
        f(this.f2319c);
    }

    private boolean e(CharSequence charSequence) {
        boolean z2 = true;
        if (s.x(this.f2317a) != 1) {
            z2 = false;
        }
        return (z2 ? e.f1287d : e.f1286c).a(charSequence, 0, charSequence.length());
    }

    private void f(float f2) {
        int i2;
        TextPaint textPaint;
        z(f2);
        this.q = C(this.o, this.p, f2, this.L);
        this.r = C(this.m, this.n, f2, this.L);
        W(C(this.i, this.j, f2, this.M));
        if (this.l != this.k) {
            textPaint = this.J;
            i2 = a(r(), p(), f2);
        } else {
            textPaint = this.J;
            i2 = p();
        }
        textPaint.setColor(i2);
        this.J.setShadowLayer(C(this.R, this.N, f2, (TimeInterpolator) null), C(this.S, this.O, f2, (TimeInterpolator) null), C(this.T, this.P, f2, (TimeInterpolator) null), a(q(this.U), q(this.Q), f2));
        s.W(this.f2317a);
    }

    private void g(float f2) {
        float f3;
        boolean z2;
        boolean z3;
        if (this.x != null) {
            float width = (float) this.e.width();
            float width2 = (float) this.f2320d.width();
            boolean z4 = true;
            if (A(f2, this.j)) {
                f3 = this.j;
                this.F = 1.0f;
                Typeface typeface = this.u;
                Typeface typeface2 = this.s;
                if (typeface != typeface2) {
                    this.u = typeface2;
                    z2 = true;
                } else {
                    z2 = false;
                }
            } else {
                float f4 = this.i;
                Typeface typeface3 = this.u;
                Typeface typeface4 = this.t;
                if (typeface3 != typeface4) {
                    this.u = typeface4;
                    z3 = true;
                } else {
                    z3 = false;
                }
                if (A(f2, this.i)) {
                    this.F = 1.0f;
                } else {
                    this.F = f2 / this.i;
                }
                float f5 = this.j / this.i;
                width = width2 * f5 > width ? Math.min(width / f5, width2) : width2;
                f3 = f4;
                z2 = z3;
            }
            if (width > 0.0f) {
                z2 = this.G != f3 || this.I || z2;
                this.G = f3;
                this.I = false;
            }
            if (this.y == null || z2) {
                this.J.setTextSize(this.G);
                this.J.setTypeface(this.u);
                TextPaint textPaint = this.J;
                if (this.F == 1.0f) {
                    z4 = false;
                }
                textPaint.setLinearText(z4);
                CharSequence ellipsize = TextUtils.ellipsize(this.x, this.J, width, TextUtils.TruncateAt.END);
                if (!TextUtils.equals(ellipsize, this.y)) {
                    this.y = ellipsize;
                    this.z = e(ellipsize);
                }
            }
        }
    }

    private void h() {
        Bitmap bitmap = this.B;
        if (bitmap != null) {
            bitmap.recycle();
            this.B = null;
        }
    }

    private void j() {
        if (this.B == null && !this.f2320d.isEmpty() && !TextUtils.isEmpty(this.y)) {
            f(0.0f);
            this.D = this.J.ascent();
            this.E = this.J.descent();
            TextPaint textPaint = this.J;
            CharSequence charSequence = this.y;
            int round = Math.round(textPaint.measureText(charSequence, 0, charSequence.length()));
            int round2 = Math.round(this.E - this.D);
            if (round > 0 && round2 > 0) {
                this.B = Bitmap.createBitmap(round, round2, Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(this.B);
                CharSequence charSequence2 = this.y;
                canvas.drawText(charSequence2, 0, charSequence2.length(), 0.0f, ((float) round2) - this.J.descent(), this.J);
                if (this.C == null) {
                    this.C = new Paint(3);
                }
            }
        }
    }

    private int q(ColorStateList colorStateList) {
        if (colorStateList == null) {
            return 0;
        }
        int[] iArr = this.H;
        return iArr != null ? colorStateList.getColorForState(iArr, 0) : colorStateList.getDefaultColor();
    }

    private int r() {
        return q(this.k);
    }

    private void x(TextPaint textPaint) {
        textPaint.setTextSize(this.j);
        textPaint.setTypeface(this.s);
    }

    private void y(TextPaint textPaint) {
        textPaint.setTextSize(this.i);
        textPaint.setTypeface(this.t);
    }

    private void z(float f2) {
        this.f.left = C((float) this.f2320d.left, (float) this.e.left, f2, this.L);
        this.f.top = C(this.m, this.n, f2, this.L);
        this.f.right = C((float) this.f2320d.right, (float) this.e.right, f2, this.L);
        this.f.bottom = C((float) this.f2320d.bottom, (float) this.e.bottom, f2, this.L);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:4:0x000a, code lost:
        r0 = r1.k;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final boolean B() {
        /*
            r1 = this;
            android.content.res.ColorStateList r0 = r1.l
            if (r0 == 0) goto L_0x000a
            boolean r0 = r0.isStateful()
            if (r0 != 0) goto L_0x0014
        L_0x000a:
            android.content.res.ColorStateList r0 = r1.k
            if (r0 == 0) goto L_0x0016
            boolean r0 = r0.isStateful()
            if (r0 == 0) goto L_0x0016
        L_0x0014:
            r0 = 1
            goto L_0x0017
        L_0x0016:
            r0 = 0
        L_0x0017:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.internal.a.B():boolean");
    }

    /* access modifiers changed from: package-private */
    public void D() {
        this.f2318b = this.e.width() > 0 && this.e.height() > 0 && this.f2320d.width() > 0 && this.f2320d.height() > 0;
    }

    public void E() {
        if (this.f2317a.getHeight() > 0 && this.f2317a.getWidth() > 0) {
            b();
            d();
        }
    }

    public void G(int i2, int i3, int i4, int i5) {
        if (!F(this.e, i2, i3, i4, i5)) {
            this.e.set(i2, i3, i4, i5);
            this.I = true;
            D();
        }
    }

    public void H(Rect rect) {
        G(rect.left, rect.top, rect.right, rect.bottom);
    }

    public void I(int i2) {
        d dVar = new d(this.f2317a.getContext(), i2);
        ColorStateList colorStateList = dVar.f1923b;
        if (colorStateList != null) {
            this.l = colorStateList;
        }
        float f2 = dVar.f1922a;
        if (f2 != 0.0f) {
            this.j = f2;
        }
        ColorStateList colorStateList2 = dVar.f;
        if (colorStateList2 != null) {
            this.Q = colorStateList2;
        }
        this.O = dVar.g;
        this.P = dVar.h;
        this.N = dVar.i;
        c.b.a.b.z.a aVar = this.w;
        if (aVar != null) {
            aVar.c();
        }
        this.w = new c.b.a.b.z.a(new C0101a(), dVar.e());
        dVar.h(this.f2317a.getContext(), this.w);
        E();
    }

    public void J(ColorStateList colorStateList) {
        if (this.l != colorStateList) {
            this.l = colorStateList;
            E();
        }
    }

    public void K(int i2) {
        if (this.h != i2) {
            this.h = i2;
            E();
        }
    }

    public void L(Typeface typeface) {
        if (M(typeface)) {
            E();
        }
    }

    public void N(int i2, int i3, int i4, int i5) {
        if (!F(this.f2320d, i2, i3, i4, i5)) {
            this.f2320d.set(i2, i3, i4, i5);
            this.I = true;
            D();
        }
    }

    public void O(Rect rect) {
        N(rect.left, rect.top, rect.right, rect.bottom);
    }

    public void P(int i2) {
        d dVar = new d(this.f2317a.getContext(), i2);
        ColorStateList colorStateList = dVar.f1923b;
        if (colorStateList != null) {
            this.k = colorStateList;
        }
        float f2 = dVar.f1922a;
        if (f2 != 0.0f) {
            this.i = f2;
        }
        ColorStateList colorStateList2 = dVar.f;
        if (colorStateList2 != null) {
            this.U = colorStateList2;
        }
        this.S = dVar.g;
        this.T = dVar.h;
        this.R = dVar.i;
        c.b.a.b.z.a aVar = this.v;
        if (aVar != null) {
            aVar.c();
        }
        this.v = new c.b.a.b.z.a(new b(), dVar.e());
        dVar.h(this.f2317a.getContext(), this.v);
        E();
    }

    public void Q(ColorStateList colorStateList) {
        if (this.k != colorStateList) {
            this.k = colorStateList;
            E();
        }
    }

    public void R(int i2) {
        if (this.g != i2) {
            this.g = i2;
            E();
        }
    }

    public void S(float f2) {
        if (this.i != f2) {
            this.i = f2;
            E();
        }
    }

    public void T(Typeface typeface) {
        if (U(typeface)) {
            E();
        }
    }

    public void V(float f2) {
        float a2 = b.f.g.a.a(f2, 0.0f, 1.0f);
        if (a2 != this.f2319c) {
            this.f2319c = a2;
            d();
        }
    }

    public void X(TimeInterpolator timeInterpolator) {
        this.L = timeInterpolator;
        E();
    }

    public final boolean Y(int[] iArr) {
        this.H = iArr;
        if (!B()) {
            return false;
        }
        E();
        return true;
    }

    public void Z(CharSequence charSequence) {
        if (charSequence == null || !TextUtils.equals(this.x, charSequence)) {
            this.x = charSequence;
            this.y = null;
            h();
            E();
        }
    }

    public void a0(TimeInterpolator timeInterpolator) {
        this.M = timeInterpolator;
        E();
    }

    public void b0(Typeface typeface) {
        boolean M2 = M(typeface);
        boolean U2 = U(typeface);
        if (M2 || U2) {
            E();
        }
    }

    public float c() {
        if (this.x == null) {
            return 0.0f;
        }
        x(this.K);
        TextPaint textPaint = this.K;
        CharSequence charSequence = this.x;
        return textPaint.measureText(charSequence, 0, charSequence.length());
    }

    public void i(Canvas canvas) {
        float f2;
        int save = canvas.save();
        if (this.y != null && this.f2318b) {
            float f3 = this.q;
            float f4 = this.r;
            boolean z2 = this.A && this.B != null;
            if (z2) {
                f2 = this.D * this.F;
            } else {
                f2 = this.J.ascent() * this.F;
                this.J.descent();
            }
            if (z2) {
                f4 += f2;
            }
            float f5 = f4;
            float f6 = this.F;
            if (f6 != 1.0f) {
                canvas.scale(f6, f6, f3, f5);
            }
            if (z2) {
                canvas.drawBitmap(this.B, f3, f5, this.C);
            } else {
                CharSequence charSequence = this.y;
                canvas.drawText(charSequence, 0, charSequence.length(), f3, f5, this.J);
            }
        }
        canvas.restoreToCount(save);
    }

    public void k(RectF rectF) {
        boolean e2 = e(this.x);
        Rect rect = this.e;
        float c2 = !e2 ? (float) rect.left : ((float) rect.right) - c();
        rectF.left = c2;
        Rect rect2 = this.e;
        rectF.top = (float) rect2.top;
        rectF.right = !e2 ? c2 + c() : (float) rect2.right;
        rectF.bottom = ((float) this.e.top) + n();
    }

    public ColorStateList l() {
        return this.l;
    }

    public int m() {
        return this.h;
    }

    public float n() {
        x(this.K);
        return -this.K.ascent();
    }

    public Typeface o() {
        Typeface typeface = this.s;
        return typeface != null ? typeface : Typeface.DEFAULT;
    }

    public int p() {
        return q(this.l);
    }

    public int s() {
        return this.g;
    }

    public float t() {
        y(this.K);
        return -this.K.ascent();
    }

    public Typeface u() {
        Typeface typeface = this.t;
        return typeface != null ? typeface : Typeface.DEFAULT;
    }

    public float v() {
        return this.f2319c;
    }

    public CharSequence w() {
        return this.x;
    }
}
